package ir.blocks;

import ir.Block;
import ir.CellUnit;
import ir.StructuralDefinition;

import java.util.ArrayList;
import java.util.List;

import run.Cell;
import run.Facet;

/**
 * A block representing a single unit:
 * 	MYCELL
 * @author Thomas Chau
 *
 */
public class UnitBlk extends Block {
	
	private Cell cell;
	
	/**
	 * Get the Unit's facets eligible for Left. [X|]
	 */
	@Override
	public List<Facet> getLeftFacets(StructuralDefinition d) {
		if ( cell == null) {
			CellUnit cellUnit = units.get(0);
			cell = cellUnit.genesis(d);
		}
		
		return cell.getInFacets();
	}

	/**
	 * Get the unit's facets eligible for Right binding. [|X]
	 */
	@Override
	public List<Facet> getRightFacets(StructuralDefinition d) {
		if ( cell == null) {
			CellUnit cellUnit = units.get(0);
			cell = cellUnit.genesis(d);
		}
		
		return cell.getOutFacets();
	}
	
	// has only one unit
	public CellUnit getUnit() {
		return units.get(0);
	}
	
	public UnitBlk clone() {
		UnitBlk unitBlk = new UnitBlk();
		unitBlk.add(units.get(0).clone());
		return unitBlk;
	}
}
